<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class Manager extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'username' => 'require|length:6,10',
        'password' => 'require|length:2,8',
        'email' => 'require|email'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require' => "用户名必填",
        'username.length' => "用户名长度不能少于6位",
        'password.require' => "密码必填",
        'password.length' => "密码长度不能少于6位",
        'email.require' => "邮箱必填必填",
        'email.email' => "邮箱格式不正确",
    ];

    // 回顾验证场景 scene + 场景名
    public function sceneUpdate(){
//        针对于编辑的场景
        return $this->remove('password','require|length')->append('phone',['require']);
    }
}
